package com.youmu.sichuansfc.dao.impl;

import com.youmu.sichuansfc.dao.FundManagerPartnerDao;
import com.youmu.sichuansfc.domain.YoumuFundManagerPartner;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;


@Repository
public class FundManagerPartnerDaoImpl implements FundManagerPartnerDao {

    private EntityManager em;
    @PersistenceContext
    public void setEm(EntityManager em) {
        this.em = em;
    }

    @Override
    public List<YoumuFundManagerPartner> findByManagerId(Long managerId) {
        String sql  = "from YoumuFundManagerFundInvest where is_delete = 0 and fund_manager_id = :managerId";

        return  em.createQuery(sql, YoumuFundManagerPartner.class)
                .setParameter("managerId", managerId)
                .getResultList();
    }

    @Override
    public YoumuFundManagerPartner upload(YoumuFundManagerPartner youmuFundManagerPartner) {
        if(youmuFundManagerPartner.getId() != null){
            youmuFundManagerPartner = em.merge(youmuFundManagerPartner);
        }else {
            em.persist(youmuFundManagerPartner);
        }
        return  youmuFundManagerPartner;
    }
}
